import { HttpsProxyAgent } from 'https-proxy-agent';


export function createAgent(proxy) {
  if (proxy == null) {
    return null
  }
  proxy = proxy.replace("http://", "")
  proxy = proxy.replace("socks5://", "")
  const proxyArr = proxy.split(":")
  let agentUrl = ""
  if (proxyArr.length == 2) {
    agentUrl = `http://${proxyArr[0]}:${proxyArr[1]}`
  } else if (proxyArr.length == 4) {
    agentUrl = `http://${proxyArr[2]}:${proxyArr[3]}@${proxyArr[0]}:${proxyArr[1]}`
  }
  const agent = new HttpsProxyAgent(agentUrl)
  return agent
}